﻿using System.Windows;
using System.Windows.Forms;
using RandomSearch.VM;
using ComboBox = System.Windows.Controls.ComboBox;

namespace RandomSearch.ClientUi
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void SelectPath_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new FolderBrowserDialog();
            DialogResult result = dialog.ShowDialog(this.GetIWin32Window());
            if (System.Windows.Forms.DialogResult.OK == result)
            {
                SettingsPath.Text = dialog.SelectedPath;
            }
        }

        private void Wnd_Closing(object sender, System.ComponentModel.CancelEventArgs _)
        {
            var e = Resources["VMModel"] as VM.ViewModel;
            if (null != e) e.Dispose();
        }

        private void SelectedPlugin_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            var cb = (ComboBox)sender;
            var obj = cb.SelectedItem as PluginItem;
            if (null == ExSettings) return;
            
            if (null != obj && null != obj.Settings) {
                ExSettings.Children.Clear();
                ExSettings.Children.Add(obj.Settings);
                ExSettings.Visibility = Visibility.Visible;
            }
            else {
                ExSettings.Visibility = Visibility.Collapsed;
            }
        }
    }
}